home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE21 / EX15.C < prev    next >
C/C++ Source or Header  |  1995-05-29  |  3KB  |  69 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.    static char szOriginalLabel[128];
  6.    static char szRootPath[MAX_PATH + 1];
  7.  
  8.    switch (uMsg)
  9.    {
  10.          case WM_CREATE:
  11.          {
  12.                // Make root path name
  13.                GetCurrentDirectory( MAX_PATH, szRootPath );
  14.                szRootPath[3] = 0;
  15.                // Store label for later restore.
  16.                GetVolumeInformation( szRootPath, szOriginalLabel,
  17.                                      sizeof( szOriginalLabel ) - 1,
  18.                                      NULL, NULL, NULL, NULL, 0 );
  19.          }
  20.          return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  21.          case WM_COMMAND:
  22.                switch ( LOWORD( wParam ) )
  23.                {
  24.                      case IDM_TEST:
  25.                      {
  26.                            LPTSTR lpTemp;
  27.                            char   szLabel[MAX_PATH + 1];
  28.                            char   szCommandLine[MAX_PATH+1];
  29.                            char   szBuffer[2 * MAX_PATH + 32];
  30.  
  31.                            GetVolumeInformation( szRootPath, szLabel,
  32.                                                  sizeof( szLabel ) - 1,
  33.                                                  NULL, NULL, NULL, NULL, 0 );
  34.  
  35.                            lstrcpy( szCommandLine, GetCommandLine() );
  36.                            // Search for extra input after program name.
  37.                            lpTemp = strstr( szCommandLine, " " );
  38.                            if (lpTemp)
  39.                               lpTemp = strtok(lpTemp, " ");
  40.  
  41.                            if (lpTemp)
  42.                            {
  43.                               wsprintf( szBuffer,
  44.                                         "Orig Label: [%s], Current Label: [%s]",
  45.                                         szOriginalLabel, szLabel );
  46.                               MessageBox( hWnd, szBuffer, "Changing Volume Label",
  47.                                           MB_OK );
  48.                               SetVolumeLabel( szRootPath, lpTemp );
  49.                            }
  50.                            else
  51.                               MessageBox( hWnd, szOriginalLabel,
  52.                                           "Volume Label", MB_OK );
  53.                      }
  54.                      break;
  55.                      case IDM_EXIT:
  56.                            DestroyWindow( hWnd );
  57.                            break;
  58.                }
  59.                break;
  60.          case WM_DESTROY:
  61.                // Restore old label name.
  62.                SetVolumeLabel( szRootPath, szOriginalLabel );
  63.                PostQuitMessage( 0 );
  64.                break;
  65.          default:
  66.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  67.    }
  68.    return (NULL);
  69. }